const Vue=require('vue');

const server =require('express')();

const renderer=require('vue-server-renderer').createRenderer({
    template:require('fs').readFileSync('./ssrTemplate/index.html','utf-8')
});
const context={
    title:'你好',
    meta:`
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
    `
}
server.get('*',(req,res)=>{
   const app=new Vue({
       data:{
           url:req.url
       },
       template:`<div>访问的是 {{url}}</div>`
   });

    renderer.renderToString(app,context,(err,html)=>{
        if (err) {
            res.status(500).end('Internal Server Error')
            return
        }
        res.end(`
        <!DOCTYPE html>
        <html>
            <head>
                <title>Hello -- world</title>
                <meta charset="UTF-8">
            </head>
            <body>${html}</body>
        </html>
        `)

    })
});

server.listen(9999);


